//
//  NewfeatureViewController.m
//  WB3
//
//  Created by Ruan on 14-9-5.
//  Copyright (c) 2014年 sinaweibo. All rights reserved.
//

#import "NewfeatureViewController.h"
#import "RootViewController.h"
#define kCount 3

@interface NewfeatureViewController ()
@property(nonatomic,strong)UIScrollView *scroll;
@property(nonatomic,strong)UIPageControl *page;
@property(nonatomic,strong)UIButton *button;
@end

@implementation NewfeatureViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)loadView
{
    [super loadView];
    [UIApplication sharedApplication].statusBarHidden = NO;
//    UIImageView *imageView = [[UIImageView alloc] init];
//    UIImage *image = [UIImage imageNamed:@"page3"];
//    imageView.image = image;
//    imageView.frame = [UIScreen mainScreen].bounds;
//    self.view = imageView;
//    imageView.userInteractionEnabled = YES;
//    [imageView release];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    UIScrollView *scroll = [[UIScrollView alloc] init];
    scroll.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
    scroll.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width * kCount, 0);
    scroll.showsHorizontalScrollIndicator = NO;
    scroll.pagingEnabled = YES;
    scroll.bounces = NO;
 
    
    for (int i = 0; i < kCount; i++) {
        NSString *imageName = [NSString stringWithFormat:@"page%d",i + 1];
        UIImage *image = [UIImage imageNamed:imageName];
        UIImageView *imageView = [[UIImageView alloc] init];
        imageView.image = image;
        imageView.frame = CGRectMake(image.size.width * i, 0, image.size.width , image.size.height);
        if (i == kCount - 1) {
            UIButton *startBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            [startBtn setBackgroundImage:[UIImage imageNamed:@"start"] forState:UIControlStateNormal];
                        startBtn.frame = CGRectMake(0, 0, startBtn.currentBackgroundImage.size.width, startBtn.currentBackgroundImage.size.height);
            startBtn.center = CGPointMake(scroll.bounds.size.width * 0.5 , scroll.bounds.size.height * 0.6);
            [startBtn addTarget:self action:@selector(startClick:) forControlEvents:UIControlEventTouchUpInside];
            imageView.userInteractionEnabled = YES;
            [imageView addSubview:startBtn];
        }
        
        [scroll addSubview:imageView];
        [imageView release];
    }
    
    scroll.delegate = self;
    self.scroll = scroll;
    [self.view addSubview:scroll];
    
    
    UIPageControl * page = [[UIPageControl alloc] init];
    page.frame = CGRectMake(0, 0, 300, 50);
    page.center = CGPointMake([UIScreen mainScreen].bounds.size.width * 0.5, [UIScreen mainScreen].bounds.size.height * 0.94);
    page.numberOfPages = kCount;
    page.currentPage = 0;
    page.pageIndicatorTintColor = [UIColor lightGrayColor];
    page.currentPageIndicatorTintColor = [UIColor darkGrayColor];
    self.page = page;
    [page addTarget:self action:@selector(pageClick:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:page];
    [scroll release];
    [page release];
}


 - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    int count = self.scroll.contentOffset.x / self.scroll.bounds.size.width;

    self.page.currentPage = count ;

}

- (void)pageClick:(UIPageControl *)pageClick
{
    self.scroll.contentOffset = CGPointMake(self.page.currentPage * self.scroll.bounds.size.width,0);
}

- (void)startClick:(UIButton *)btn
{
    RootViewController *rootVC = [[RootViewController alloc] init];
    self.view.window.rootViewController = rootVC;
    [rootVC release];

}





- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc
{
    [super dealloc];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
